# Define a list of FPChecks to match against data and a list of FPEntities with associated patterns with a relative value for each entity

from FPCheck import *
from FPEntity import *
from log import log

class FPContainer(object):
	fpchecks={}
	fpentities={}
	global_value=0
	global_matched=0
	def __init__(self):
		pass

	def add_fpcheck(self,fpcheck):
		self.fpchecks[fpcheck.pattern]=fpcheck

	def add_fpchecks(self,fpcheck_dict={}):
		if self.fpchecks:
			self.fpchecks.update(fpcheck_dict)
		else:
			self.fpchecks=fpcheck_dict
		log("Added "+str(len(fpcheck_dict))+" to container "+ str(self))

	def add_fpchecks_from_entities(self):
		for ent in self.fpentities.values():
			self.add_fpchecks(ent.get_fpchecks())

	def __check(self,data):
		if self.fpchecks:
			for fpcheck in self.fpchecks.values():
				self.global_matched=self.global_matched+fpcheck.check(data)

	def add_fpentity(self, fpentity):
		self.fpentities[fpentity.name]=fpentity

	def check_entities(self,data):
		self.__check(data)
		for fpentity in self.fpentities.values():
			fpentity.get_score(self.fpchecks)
			if fpentity.is_alert():
				print ""
				print fpentity.name + " is alert with this score " + str(fpentity.score)
				print ""
			else:
				print ""
				print fpentity.name + " is not alert with this score " + str(fpentity.score)
				print ""

	def clear(self):
		self.clear_fpchecks()
		for fpentity in self.fpentities.values():
			fpentity.clear()
			
	def clear_fpchecks(self):
		if self.fpchecks:
			for fpcheck in self.fpchecks.values():
				fpcheck.matched=0
		
		
